/*公共方法*/

var fnBase = {

	splitURL: function() { //分割url
		var url = document.location.href,
			argsArray = [],
			i, len, argsName, argsVal, obj = {};
		if(url.indexOf('?') != -1) {
			argsArray = url.split("?")[1].split("&");
			len = argsArray.length;
			for(i = 0; i < len; i++) {
				argsName = argsArray[i].split("=")[0];
				argsVal = argsArray[i].split("=")[1];
				obj[argsName] = decodeURIComponent(argsVal);
			}
		}
		return obj
	},

	/*显示loading*/
	loadShow: function() {
		$("<div class='black_loading' style='display: block'><img src='images/loading.gif' /></div>").appendTo($('body'))
	},
	/*删除loading*/
	loadHide: function() {
		$('.black_loading').remove()
	},
	deletetext: function() {
		$("<div class='deletetext'>该文章已被删除</div>").appendTo($('body'));
	},
	linkError: function() {
		$("<dl class='linkerror'><dt><img src='images/icon_wlan@2x.png'/></dt><dd>网络被吃掉了</dd></dl>").appendTo($('body'));
	},
	api: {
		post_ArticleInfo: "https://gaokao.dashu360.com/CommArticle/ArticleInfo.html", // 帖子详情
		post_ArticleReplayInfo: "https://gaokao.dashu360.com/CommArticle/ArticleReplayInfo.html", //帖子回复详情
		post_ArticleReplyMore: "https://gaokao.dashu360.com/CommArticle/ArticleReplyMore.html", //查看二级回复更多
		post_ArticleReplyLaud: "https://gaokao.dashu360.com/CommArticle/ArticleReplyLaud.html", //文章评论点赞
		post_ArticleCollect: "https://gaokao.dashu360.com/CommArticle/ArticleCollect.html", //收藏文章
		post_ArticleLaud: "https://gaokao.dashu360.com/CommArticle/ArticleLaud.html", //文章点赞
		post_ArticleReplyAdd:"https://gaokao.dashu360.com/CommArticle/ArticleReplyAdd.html",// 回复帖子
		post_ArticleCollect:"https://gaokao.dashu360.com/CommArticle/ArticleCollect.html",//帖子收藏
		post_ArticleCollectCancel:"https://gaokao.dashu360.com/CommArticle/ArticleCollectCancel.html",//帖子取消收藏

		Info_InformInfo:"https://gaokao.dashu360.com/Inform/InformInfo.html",//资讯详情
		Info_InformReplayInfo:"https://gaokao.dashu360.com/Inform/InformReplayInfo.html",//资讯回复详情
		Info_InformLaud:"https://gaokao.dashu360.com/Inform/InformLaud.html",//资讯点赞
		Info_InformReplyMore:"https://gaokao.dashu360.com/Inform/InformReplyMore.html",//资讯二级回复更多
		Info_InformReplyLaud:"https://gaokao.dashu360.com/Inform/InformReplyLaud.html",//资讯回复点赞
		Info_InformReplyAdd:"https://gaokao.dashu360.com/Inform/InformReplyAdd.html",//资讯回复
		Info_InformCollect:"https://gaokao.dashu360.com/Inform/InformCollect.html",//资讯收藏
		Info_InformCollectCancel:"https://gaokao.dashu360.com/Inform/InformCollectCancel.html",//资讯取消收藏

		MajorTypeList:"https://gaokao.dashu360.com/major/MajorTypeList.html",//专业大全
		MajorForTypeList:"https://gaokao.dashu360.com/major/MajorForTypeList.html",//专业大全下级分类
		MajorInfo:"https://gaokao.dashu360.com/major/MajorInfo",//专业详情
		MajorCollege:"https://gaokao.dashu360.com/major/CollegeMajor",//专业开设院校
		MajorCollegeRank:"https://gaokao.dashu360.com/major/CollegeRank",//专业学校排名
		MajorCollect:"https://gaokao.dashu360.com/major/MajorCollect.html",//专业收藏
		MajorCollectCancel:"https://gaokao.dashu360.com/major/MajorCollectCancel.html",//取消专业收藏

		VolunteerCollege:"https://gaokao.dashu360.com/College.html",//报志愿

		BatchScoreList:"https://gaokao.dashu360.com/College/BatchScoreList.html",//批次线

		School_InformCollect:"https://gaokao.dashu360.com/College/InformCollect.html",//收藏学校
		School_InformCollectCancel:"https://gaokao.dashu360.com/College/InformCollectCancel.html",//取消学校收藏
		School_CollegeInfo:"https://gaokao.dashu360.com/College/CollegeInfo.html",//学校详情
		School_CollegeMajorScore:"https://gaokao.dashu360.com/College/CollegeMajorScore.html",//专业录取平均分

		School_img:"http://sinastorage.com/kaoshi.edu.sina.com.cn/college_logo/",//学校图
	},
	versions: function() { //判断设备类型
		var u = navigator.userAgent,
			app = navigator.appVersion;
		return { //移动终端浏览器版本信息
			presto: u.indexOf('Presto') > -1, //opera内核
			webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
			gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
			mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
			ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
			android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
			iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
			iPad: u.indexOf('iPad') > -1, //是否iPad
			webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
		};
	}(),
	myAlert: function(msg, duration, callback) { //弹出层
		//if (!msg) return;
		duration = typeof duration == 'number' ? duration : 1.2;
		var BODY = document.querySelector('body'),
			TIMER = null;
		clearTimeout(TIMER);

		function fillToast() {
			var toast = document.createElement('div');
			toast.id = 'showToast';
			toast.innerHTML = msg;
			toast.style.display = 'block';
			BODY.appendChild(toast);
		}
		if(!!document.getElementById("showToast")) {
			BODY.removeChild(document.getElementById('showToast'));
			fillToast();
		} else {
			fillToast();
		}
		TIMER = setTimeout(function() {
			if(!!document.getElementById("showToast")) {
				BODY.removeChild(document.getElementById('showToast'));
			}
			callback && callback();
		}, duration * 1000);

	},
	//toast
	toast: function(text,myTop) {

		var Toast = function(config) {

			this.context = config.context == null ? $('body') : config.context; //上下文
			this.message = config.message; //显示内容  
			this.time = config.time == null ? 5000 : config.time; //持续时间  
			this.left = config.left; //距容器左边的距离  
			this.top = myTop == null ? config.top : myTop ; //距容器上方的距离  
			this.init();
		}
		var msgEntity;
		Toast.prototype = {
			//初始化显示的位置内容等  
			init: function() {
				$("#toastMessage").remove();
				//设置消息体  
				var msgDIV = new Array();
				msgDIV.push('<div id="toastMessage" style="text-align: center;border-radius:5px;background: rgba(0, 0, 0, 0.8);">');
				msgDIV.push('<span>' + this.message + '</span>');
				msgDIV.push('</div>');
				msgEntity = $(msgDIV.join('')).appendTo(this.context);
				//设置消息样式  
				var left = this.left == null ? this.context.width() / 2 - (msgEntity.find('span').width() / 2) : this.left;
				var top = this.top == null ? '50%' : this.top;
				msgEntity.css({
					position: 'fixed',
					bottom: top,
					'z-index': '9999',
					left: '25%',
					color: 'white',
					'font-size': '15px',
					padding: '10px',
					width:'50%',
					'min-height':'1.0rem',
				});
				//msgEntity.hide();
			},
			//显示动画
			show: function() {
				msgEntity.fadeIn(this.time/ 2);
				msgEntity.fadeOut(this.time/2);
			}

		}
		new Toast({context:$('body'),message:text}).show();
	},
	//阻止页面滑动
	stopSlide:function(){
		document.addEventListener('touchmove',function(e){window.event.returnValue = false;},false);
	},
	//可以滑动
	allowSlide:function(){
		document.addEventListener('touchmove',function(e){window.event.returnValue = true;},false);
	},
	/*ajax方法*/
    commonAjax : function(url,data,fn){
        $.ajax({
           	data : data,
            url : url,
            timeout:60000,
            dataType : "json",
            type : "post",
            success : function(data) {
            	//console.log(data);
				fn(data);//执行自定义的回调方法 fn
            },
            error:function(){
                /*数据请求失败*/
				fnBase.toast("亲！页面出错了，努力修复中。");
            }
        });
    },
	//时间格式
	formatDate: function(date) {
		var m = date.getMonth() + 1;
		var d = date.getDate();
		var h = date.getHours();
		var mi = date.getMinutes();
		m = m > 9 ? m : '0' + m;
		d = d > 9 ? d : '0' + d;
		return m + '-' + d + ' ' + h + ':' + mi;
	},
	Trim: function(str) {
		return str.replace(/(^\s*)|(\s*$)/g, "");
	},
	check_string: {

		isMobile: function(a) {
			if(!a) {
				return false
			}
			var b = /^1[3|4|5|7|8]\d{9}$/;
			return b.test(a)
		},
		isPassword: function(a) {
			if(!a) {
				return false
			}
			var b = /^[a-zA-Z0-9]{6,18}$/;
			return b.test(a)
		},
		isEmail: function(a) {
			if(!a) {
				return false
			}
			var b = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/;
			return b.test(a)
		},
		countVal: function(a) {
			if(!a) {
				return false
			}
			return a.replace(/[\u4E00-\u9FA5]/g, "@@").length
		},
		trim: function(a) {
			if(!a) {
				return false
			}
			return a.replace(/(^\s*)|(\s*$)/g, "")
		},
		encode: function(a) {
			if(!a) {
				return false
			}
			return a.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\\/g, "&#92;").replace(/"/g, "&quot;").replace(/'/g, "&#39;")
		},
		isCode: function(b) {
			var a = /^\d+$/g;
			if(!b) {
				return false
			}
			return a.test(b)
		},
		isNumber: function(a) {
			if(!a) {
				return false
			}
			var b = /^[1-9][0-9]*$/;
			return b.test(a)
		},
		isName: function(a) {
			if(!$.trim(a)) {
				return false
			}
			var b = /^([a-zA-Z\u4e00-\u9fa5]){2,30}$/;
			return b.test(a)
		}
	},
	isLogin: function(a) {
		if(a == '' || a == '(null)' || a == '(nil)' || a == null || a == 'null' || typeof(a) == 'undefined' || typeof(a) == 'null' || a == 'undefined' || a == undefined || a == '0') {
			//alert(1,a)
			return false
		} else {
			//alert(a)
			return true
		}
	},
}